package com.thread.sync;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

public class SynchronizedTest {

    public synchronized static void mA(){
        for(;;){
            System.out.println("method A!");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static synchronized void mB(){
        for(;;){
            System.out.println("method B!");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void mC(){
        for(;;){
            System.out.println("method C!");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void mD(){
        for(;;){
            System.out.println("method D!");
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void mF(){
        System.out.println("start...");
        synchronized (Object.class){
            for(int i=0; i<=5; i++){
                System.out.println("method F!" + Thread.currentThread().getName());
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
        System.out.println("end...");
    }
}
